function fcut = limitedAngleCut( img, angl ,varargin )
%



low=true;
random=false;
par=1;
if(nargin>2)
    par=varargin{1};
end

trueimg=img;
angl=angl*pi/360;
[n,m]=size(img);
origin=get_origin([n,m]);
[X,Y]=meshgrid(1-origin(1):n-origin(1),1-origin(2):m-origin(2));
[theta,rad]=cart2pol(X,Y);

fcut=((abs(theta)<=angl)+(abs(theta)>=pi-angl));
fcut(origin)=1;

if(low)
    fcut(origin(1)-1:origin(1)+1,origin(2)-1:origin(2)+1)=ones(3,3);
end

for i=1:n
    if(random)
        pos=length(fcut(fcut(1:origin(1),i)<1));
        img(1:pos,i)=(.5.*rand(pos,1)+1).*img(pos+1,i);
        pos=length(fcut(fcut(origin(1)+1:end,i)<1));
        img(n-pos:end,i)=(.5.*rand(pos+1,1)+1).*img(end-pos-1,i);
    else
        pos=length(fcut(fcut(1:origin(1),i)<1));
        img(1:pos,i)=ones(pos,1).*img(pos+1,i);
        pos=length(fcut(fcut(origin(1)+1:end,i)<1));
        img(n-pos:end,i)=ones(pos+1,1).*img(end-pos-1,i);
    end
end
fcut=fcut.*img;



max_dist=par*sqrt(rad);
distance=sin(angle(exp(1i*(-angl-theta)))).*rad;
preserve_Origin=ones(n,m);
preserve_Origin(origin)=0;
fcut=fcut+((theta<-angl).*(theta>=-pi/2).*(distance<=max_dist).*preserve_Origin.*(abs(max_dist-distance)./max_dist)).*img;
fcut=fcut+((theta<pi-angl).*(theta>pi/2).*(distance>=-max_dist).*preserve_Origin.*(abs(max_dist+distance)./max_dist)).*img;  

distance=sin(angle(exp(1i*(angl-theta)))).*rad;
fcut=fcut+((theta<=pi/2).*(theta>angl).*(distance>=-max_dist).*preserve_Origin.*(abs(max_dist+distance)./max_dist)).*img; 
fcut=fcut+((theta<-pi/2).*(theta>-pi+angl).*(distance<=max_dist).*preserve_Origin.*(abs(max_dist-distance)./max_dist)).*img;  

if(low)
    fcut(origin(1)-1:origin(1)+1,origin(2)-1:origin(2)+1)=trueimg(origin(1)-1:origin(1)+1,origin(2)-1:origin(2)+1);
end

end

